<template>
    <div class="">
      <div class="block">
        <span class="demonstration">请选择时间 </span>
        <el-date-picker
          @change="current"
          v-model="searchTime"
          type="datetimerange"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
        >
        </el-date-picker>
      </div>
    </div>
  </template>
  <script >
  
  export default {
    data() {
      return {
        date: new Date(),
      tableData: [],
      sysDataAllLogUrl: [],
      startTime: "", //起始日期
      endTime: "", //结束日期
      todayLogs: [],
      lastWeekLogs: [],
      last30DaysLogs: [],
      devices: {},
      value: null,
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "今天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
        disabledDate(time) {
          let limit = Date.now() - 3600 * 1000 * 24 * 30;
          return time.getTime() > Date.now() || time.getTime() < limit; // 设置禁止选今天以后的日子
        },
      },

      list: ["diyi", "dier"],
      value1: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
      searchTime: "",
      value2: "",
      //   pickerOptions: options1,
      date: "",
      date2: "",
      };
      
    },
    mounted() {
      this.fetchLogs();
    this.initData();
    },
    created() {
      console.log();
    },
    methods: {
      current() {
      console.log("当前你", this.searchTime);

      console.log("before1", this.searchTime[0]);
      console.log("before2", this.searchTime[1]);

      this.startTime = new Date(Date.parse(this.searchTime[0]));
      this.endTime = new Date(Date.parse(this.searchTime[1]));

      let startDate = this.startTime;
      let endDate = this.endTime;
      // console.log("开始", this.startTime);
      // console.log("结束", this.endTime);
      // const year=endTime.getFullYear()
      // const month=endTime.getMonth()+1
      // const day=endTime.getDate()
      this.fetchLogs(startDate, endDate);
    },
    async fetchLogs(startDate, endDate) {
      this.sysDataAllLogUrl = [];
      this.$axios
        .get("/api/getthedirfileinfo?path=log/sys/")
        .then((response) => {
          const allLogs = response.data;
          // console.log("allLogs", allLogs);
          const logTime = Object.keys(allLogs);
          console.log("111", logTime);
          // console.log("logTime", logTime);
          for (let key in allLogs) {
            if (Object.hasOwnProperty.call(allLogs, key)) {
              let logDateStr = allLogs[key].name.substring(
                0,
                allLogs[key].name.indexOf("_")
              );
              // console.log( '1',logDateStr)
              let logDate = new Date(Date.parse(logDateStr));
              // console.log("shijiancuo",logDate)
              // console.log("startTime",startDate)
              // console.log("endTime",endDate)
              if (
                typeof startDate !== "undefined" &&
                typeof endDate !== "undefined"
              ) {
                if (startDate <= logDate && endDate >= logDate) {
                  // console.log( '22',logTime)
                  this.sysDataAllLogUrl.push("/" + key);
                }
              } else {
                this.sysDataAllLogUrl.push("/" + key);
              }
            }
          }

          // console.log("5555", this.sysDataAllLogUrl);
        })
        .catch((error) => {
          console.error("Error fetching logs:", error);
        });
    },
    },
  };
  </script>
  <style scoped>
  *{
    margin:0 ;
    padding: 0;
}

.logSystem{

  width: 100%;
  height: 100vh;
  background: pink;
}
</style>